package com.qiang;

import java.util.*;

public class Test01 {
    public static void main(String[] args) {
        /*
        1  出现多少语句   .  !
   public static void method01(){}

2  一共出现了多少单词，每个出现的次数？
   public static void method01(){}

3  长度最长的单词是哪个？出现几次？
   public static void method01(){}

4  出现频率最高的单词是什么？

5  这篇文章一共多长？

6  "move to"这个字符串出现的几次，分别在什么位置出现的?

7  , : ' ?  .  ! 分别出现的次数?

8   首字母是大写的单词出现了多少次？

9  包含'i' 这个符号的单词有多少个，分别是什么？
         */

        StringBuilder sb1 = new StringBuilder();
        sb1.append("Text copyright 2005 by Stephenie Meyer. ");
        sb1.append("All rights reserved.");
        sb1.append("Little, Brown and Company.");
        sb1.append("Time Warner Book Group. ");
        sb1.append("1271 Avenue of the Americas, New York, NY 10020. ");
        sb1.append("First Edition: September 2005 .");
        sb1.append("The characters and events portrayed in this book are fictitious. ");
        sb1.append("Any similarity to real persons, living or dead, is coincidental and not !");
        sb1.append("intended by the author. ");
        sb1.append("Library of Congress Cataloging-in-Publication Data .");
        sb1.append("Twilight : a novel / by Stephanie Meyer. ");
        sb1.append("Summary: Grade 9 Up–Headstrong, sun-loving, 17-year-old Bella declines her mom's !");
        sb1.append("invitation to move to Florida, and instead reluctantly opts to move to her dad's cabin in the dreary , rainy town of Forks, WA. She becomes intrigued with Edward Cullen, a distant.");
/*
        String s2 = sb1.toString();
        String[] s = s2.split(" ");

        //无符号集合
        ArrayList<String> array = new ArrayList<>();
        //有符号集合
        ArrayList<String> arr = new ArrayList<>();


        //无符号集合
        for (int i = 0; i < s.length; i++) {
            if (s[i].length() == 0) {
                continue;
            }

            if (s[i] == "—") {
                continue;
            }
            char c = s[i].charAt(s[i].length() - 1);//最后一位
            char c1 = s[i].charAt(0);//第一位
            boolean b = c >= 'a' || c >= 'A';//最后一位
            boolean d = c1 >= 'a' || c1 >= 'A';//第一位

            if (b == false) {

                String st = s[i].substring(0, s[i].length() - 1);

                array.add(st);
            }

            if (d == false) {
                String st = s[i].substring(1, s[i].length());
                array.add(st);

            } else {
                array.add(s[i]);
            }
        }

        //有符号集合
        for (int i = 0; i < s.length; i++) {
            arr.add(s[i]);
        }*/


        StringBuilder sb2 = new StringBuilder();

        sb2.append("stylish, and disarmingly handsome senior, who is also a vampire. ");
        sb2.append("When he reveals that his specific clan hunts wildlife instead of humans. ");
        sb2.append("Bella deduces that she is safe from his blood-sucking instincts and therefore free to fall hopelessly in love with him.");
        sb2.append("The feeling is mutual, and the resulting volatile romance smolders as they attempt to hide Edward's identity from her family and the rest of the school.");
        sb2.append("Meyer adds an eerie new twist to the mismatched, star-crossed lovers theme: predator falls for prey, human falls for vampire.");
        sb2.append("This tension strips away any pretense readers may have about the everyday teen romance novel, and kissing, touching, and talking take on an entirely new meaning when one small mistake could be life-threatening.");
        sb2.append("Bella and Edward's struggle to make their relationship work becomes a struggle for survival, especially when vampires from an outside clan infiltrate the Cullen territory and head straight for her. As a result.");
        sb2.append("the novel's danger-factor skyrockets as the excitement of secret love and hushed affection morphs into a terrifying race to stay alive. ");
        sb2.append("Realistic, subtle, succinct, and easy to follow, Twilight will have readers dying to sink their teeth into it. ");
        sb2.append("For my big sister, Emily, without whose enthusiasm this story might still be unfinished. ");
        sb2.append("But of the tree of the knowledge of good and evil, thou shalt not eat of it: for in the day that thou eatest thereof  thou shalt surely die. ");
        sb2.append("I'd never given much thought to how I would die — though I'd had reason enough in the last few months — but even if I had, I would not have imagined it like this. ");
        sb2.append("I stared without breathing across the long room, into the dark eyes of the hunter, and he looked pleasantly back at me.");
        sb2.append("Surely it was a good way to die, in the place of someone else, someone I loved. Noble, even. That ought to count for something. ");
        sb2.append("I knew that if I'd never gone to Forks, I wouldn't be facing death now. ");
        sb2.append("But, terrified as I was, I couldn't bring myself to regret the decision. ");
/*
        String s1 = sb2.toString();
        String[] s3 = s1.split(" ");
        for (int i = 0; i < s3.length; i++) {
            if (s3[i].length() == 0) {
                continue;
            }

            if (s3[i] == "-") {
                continue;
            }
            char c = s3[i].charAt(s3[i].length() - 1);//最后一位
            char c1 = s3[i].charAt(0);//第一位
            boolean b = c >= 'a' | c >= 'A';
            boolean d = c1 >= 'a' | c1 >= 'A';

            if (b == false) {
                String st1 = s3[i].substring(0, s3[i].length() - 1);
                array.add(st1);
            }

            if (d == false) {
                String st1 = s3[i].substring(1, s3[i].length());
                array.add(st1);
            } else {
                array.add(s3[i]);
            }

            String[] split = s3[i].split(",");
            for (int i1 = 0; i1 < split.length; i1++) {
                array.add(split[i1]);
            }
        }


        //有符号集合
        for (int i = 0; i < s3.length; i++) {
            arr.add(s3[i]);
        }*/

        StringBuilder sb7 = new StringBuilder();

        sb7.append("When life offers you a dream so far beyond any of your expectations, it's not reasonable to grieve when it comes to an end. ");
        sb7.append("The hunter smiled in a friendly way as he sauntered forward to kill me. ");
        sb7.append("My mother drove me to the airport with the windows rolled down. ");
        sb7.append("It was seventy-five degrees in Phoenix, the sky a perfect, cloudless blue. ");
        sb7.append("I was wearing my favorite shirt — sleeveless, white eyelet lace; I was wearing it as a farewell gesture. ");
        sb7.append("My carry-on item was a parka. ");
        sb7.append("In the Olympic Peninsula of northwest Washington State, a small town named Forks exists under a near-constant cover of clouds. ");
        sb7.append("It rains on this inconsequential town more than any other place in the United States of America. ");
        sb7.append("It was from this town and its gloomy, omnipresent shade that my mother escaped with me when I was only a few months old. ");
        sb7.append("It was in this town that I'd been compelled to spend a month every summer until I was fourteen. ");
        sb7.append("That was the year I finally put my foot down; these past three summers, my dad, Charlie, vacationed with me in California for two weeks instead. ");
        sb7.append("It was to Forks that I now exiled myself— an action that I took with great horror.");
        sb7.append("I detested Forks. ");
        sb7.append("I loved Phoenix. I loved the sun and the blistering heat. ");
        sb7.append("I loved the vigorous, sprawling city. ");
        sb7.append("Bella, my mom said to me — the last of a thousand times — before I got on the plane. \"You don't have to do this.\" ");

        sb7.append(sb2);
        sb7.append(sb1);

        //无符号集合
        ArrayList<String> array = new ArrayList<>();

        //有符号集合
        ArrayList<String> arr = new ArrayList<>();

        String s8 = sb7.toString();
        String[] s9 = s8.split(" ");

        for (int i = 0; i < s9.length; i++) {
            if (s9[i].length() == 0 /*|| (Integer.parseInt(s9[i]) >= 0 && Integer.parseInt(s9[i]) <= 200000)*/) {
                continue;
            }

            char c = s9[i].charAt(s9[i].length() - 1);
            char c1 = s9[i].charAt(0);

            boolean b = c >= 'a' || c >= 'A';
            boolean d = c1 >= 'a' || c1 >= 'A';



           /* if (s9[i].length() == 1 && (d == false)) {
                array.add(s9[i]);
            }
*/
            if (b == false) {
                String st2 = s9[i].substring(0, s9[i].length() - 1);
                array.add(st2);
                continue;
            }

            if (d == false) {
                String st2 = s9[i].substring(1, s9[i].length());
                array.add(st2);
                continue;
            } else {
                array.add(s9[i]);
            }

        }


        System.out.println("========================");


        //有符号集合
        for (int i = 0; i < s9.length; i++) {
            arr.add(s9[i]);
        }


        //循环array集合,寻找一共有几句话
        int sum = 0;
        for (int i = 0; i < arr.size(); i++) {
            String s0 = arr.get(i);
            char[] ch = s0.toCharArray();
            for (int i1 = 0; i1 < ch.length; i1++) {
                if (ch[i1] == '.' || ch[i1] == '!') {
                    sum++;
                }
            }
        }
        System.out.println("一共有" + sum + "句话");


        System.out.println("========================");


        //新建一个TreeMap集合
        TreeMap<String, Integer> st = new TreeMap<>();

        for (int i = 0; i < array.size(); i++) {
            String s4 = array.get(i);
            st.put(s4, 0);
        }


        //遍历集合
        Set<String> keyset = st.keySet();
        //得到key（单词）
        for (String key : keyset) {
            Integer value = st.get(key);
            for (int i = 0; i < array.size(); i++) {
                boolean result = array.get(i).equalsIgnoreCase(key);
                if (result == true) {
                    value++;
                }
            }
            System.out.println("单词：" + key + "一共有" + value + "个");
        }

        System.out.println("========================");

        //首先遍历原集合
        //获取每个单词的长度

        TreeMap<String, Integer> sit = new TreeMap<>(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                int result = o1.length() - o2.length();
                return result;
            }
        });

        for (int i = 0; i < array.size(); i++) {
            int length = array.get(i).length();
            sit.put(array.get(i), length);
        }
        Set<String> kt = sit.keySet();
        for (String key : kt) {
            Integer value = sit.get(key);
            System.out.println("最长的单词是：" + key + "==" + "长度是：" + value);
        }

        System.out.println("========================");

        //System.out.println(123456);

        //文章一共有多长
        System.out.println("文章长度是：");
        System.out.println(arr.size());

        System.out.println("========================");


        HashSet<Character> str = new HashSet<>();
        String s = sb7.toString();
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            boolean b = chars[i] >= 'a' || chars[i] >= 'A';
            if (b == false) {
                str.add(chars[i]);
            }
        }

        //遍历str
        int num = 0;
        for (Character cha : str) {
            for (int i = 0; i < chars.length; i++) {
                if (chars[i] == cha) {
                    num++;
                }
            }
            System.out.println("字符" + cha + "有" + num + "个");
        }


        System.out.println("========================");

        //包含首字母大写的单词有多少个
        //array集合是纯单词
        //遍历集合，如果首字母是大写，就加1

        int daxie = 0;
        for (int i = 0; i < array.size(); i++) {
            String s1 = array.get(i);//得到了字符串
            //System.out.println(s1);
            if (s1.length() == 1) {
                char[] chars1 = s1.toCharArray();
                for (int i1 = 0; i1 < chars1.length; i1++) {
                    if (chars1[i1] >= 'A' & chars1[i1] <= 'Z') {
                        daxie++;
                    }
                }
            }
            if (s1.length() > 1) {
                String sub = s1.substring(0, 1);
                char[] ch = sub.toCharArray();
                for (int i1 = 0; i1 < ch.length; i1++) {
                    if (ch[i1] >= 'A' & ch[i1] <= 'Z') {
                        daxie++;
                    }
                }
            }
        }
        System.out.println("一共出现的次数是：" + daxie);


        System.out.println("========================");

        int xiaoxie = 0;

        //包含i的单词有多少个，分别是什么
        //遍历array，查看哪个单词含有i，不分大小写
        //TreeMap里面有不重复的单词
        //TreeMap<String, Integer> sit = new TreeMap<>
        //TreeMap<String, Integer> st = new TreeMap<>();

        //先遍历array单词，查看哪个单词含有i，然后拿着这个去跟另外一个集合比较，看含有多少个
        for (int i = 0; i < array.size(); i++) {
            String s1 = array.get(i);//得到了字符串
            //System.out.println(s1);
            if (s1.length() == 1) {
                if (s1.equalsIgnoreCase("i")) {
                    xiaoxie++;
                }
            }
            if (s1.length() > 1) {
                char[] ch = s1.toCharArray();
                for (int i1 = 0; i1 < ch.length; i1++) {
                    //判断是否含有i，有的换再遍历sit
                    boolean i2 = String.valueOf(ch[i1]).equalsIgnoreCase("i");
                    if (i2 == true) {
                        //Set<String> keyset = st.keySet();
                        for (String key : keyset) {
                            //xiaoxie = sit.get(key);//取得数字
                            if (s1 == key) {
                                xiaoxie++;
                                System.out.println("单词" + s1 + "含有i");
                                break;
                            }
                        }
                    }

                }
                //System.out.println("含有的i的单词一共有：" + xiaoxie);

            }

        }

        System.out.println("含有的i的单词一共有：" + xiaoxie);


    }
}
